package multithread.thread.mychongrusuo;

/**
 * Created by xi on 2019/2/17.
 */
public class MySequence {
    private int value;
    MyLock lock = new MyLock();
    public int getNext(){
         lock.lock();
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        value ++;
        lock.unlock();
        return  value;
    }
    public static void main(String[] args) {
        MySequence se = new MySequence();
        new Thread(new Runnable() {
            @Override public void run() {
                while(true)
                System.out.println("1:"+se.getNext());
            }
        }).start();

        new Thread(new Runnable() {
            @Override public void run() {
                while(true)
                System.out.println("2:"+se.getNext());
            }
        }).start();

        new Thread(new Runnable() {
            @Override public void run() {
                while(true)
                System.out.println("3:"+se.getNext());
            }
        }).start();


    }
}
